package com.medvalley.tcm.dao;

import com.medvalley.tcm.domain.YangShengSports;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface YangShengSportDao extends JpaRepository<YangShengSports,Long> {

    YangShengSports findOneBySPNameAndStatus(String sPName,int status);

    Page<YangShengSports> findAllByStatus(Pageable pageable, int status);

    @Query(nativeQuery = true, value = " SELECT   * FROM   t_yangsheng_sport t1 WHERE t1.id >=  ((SELECT MAX(id)  FROM `t_yangsheng_sport` where sptag = :spTag and status = 1) -  (SELECT  MIN(id)  FROM  t_yangsheng_sport where sptag = :spTag and status = 1)) * RAND() +  (SELECT MIN(id) FROM  t_yangsheng_sport where sptag=:spTag and status =1) and status =1 and sptag = :spTag LIMIT :num")
    List<YangShengSports> findALLByRand(@Param(value = "spTag") int spTag, @Param("num") int num);

    List<YangShengSports> findAllByIdIn(List<Long> ids);

}
